package com.site.wisdom_construction.controller.iotModule;

import com.alibaba.fastjson.JSONObject;
import com.site.wisdom_construction.responseEntity.OneDataResult;
import com.site.wisdom_construction.service.iotModule.WisdomElectricityEquipmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author daiyifei
 * @Date 2021/12/17
 * @Description
 */
@Api(tags = "智慧用电设备接口")
@RestController
@RequestMapping("WisdomElectricityEquipment")
@CrossOrigin
public class WisdomElectricityEquipmentController {
    @Autowired
    private WisdomElectricityEquipmentService wisdomElectricityEquipmentService;

    @ApiOperation(value = "接收平台推送数据", notes = "")
    @PostMapping("/insertWisdomElectricity")
    public void insertWisdomElectricity(@RequestBody Map<String, Object> map) throws IOException {
        //map转JSONObject
        JSONObject jsonObject = new JSONObject(map);
        //获取其中的data
        JSONObject jsonObjectData = jsonObject.getJSONObject("data");
        System.out.println("jsonObjectData:" + jsonObjectData);
        //传参map
        Map mapR = new HashMap();
        //大桥局标段id
        mapR.put("section_id",7);
        mapR.put("deviceNumber", jsonObject.get("deviceNumber"));
        mapR.put("sendTime", jsonObject.get("sendTime"));
        mapR.put("status", jsonObjectData.get("dataType"));

        wisdomElectricityEquipmentService.updateWisdomElectricityEquipmentByStatus(map);
    }

    @ApiOperation(value = "设备状态", notes = "")
    @PostMapping("/countWisdomElectricityEquipmentByGroup")
    public OneDataResult countWisdomElectricityEquipmentByGroup(@RequestBody Map<String, Object> map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(wisdomElectricityEquipmentService.countWisdomElectricityEquipmentByGroup(map));
        return oneDataResult;
    }
}
